const app = getApp()
import {getInfo} from '../../../api/member'
import {update} from '../../../api/user'
Page({
        data: {
                avatar:"",
                nickname:"",
                company: "",
                mobile: "",
                areaName:"",
                birthday: false,
                Invitationcod:"",
                promoterName:"",
                promoterMobile:"",
                memberType:0,
                userInfo: {},
                realAuth:app.globalData.realAuth
        },
        onLoad(options) {
        },
        onShow(){
                this.getInfo()
                this.setData({
                        nickname:app.globalData.userInfo.nickname
                })
        },
        onChooseAvatar(e){
                this.selectComponent('#uploadAvatar').uploadImg([e.detail.avatarUrl]);
        },
        metaClick(e){
                let params = {}
                params.avatar = e.detail.images[ e.detail.images.length -1 ]
                update(params).then(res => {
                        app.globalData.userInfo.avatar = e.detail.images[ e.detail.images.length -1 ]
                        this.setData({
                                avatar: res.data.avatar,
                        })
                })
        },
        getNickname: function (e){
                let params = {}
                params.nickname = e.detail.value
                update(params).then(res => {
                        app.globalData.userInfo.nickname = e.detail.value
                        this.setData({
                                nickname: e.detail.value,
                        })
                })        
        },
        toRealName(){
                wx.navigateTo({
                        url: '/pages/member/realName/realName',
                })
        },
        toResetSecret(){
                wx.navigateTo({
                        url: '/pages/member/resetSecret/resetSecret',
                })
        },
        toResetPassword(){
                wx.navigateTo({
                        url: '/pages/member/resetSecret/resetPassword',
                })
        },
        getInfo(){
                getInfo().then(res => {
                        this.data.promoterName=res.data.promoterName
                        this.data.promoterMobile=res.data.promoterMobile
                        this.data.Invitationcod=Number(res.data.member.id)+10200
                        this.data.avatar = res.data.member.avatar
                        this.data.areaName = res.data.member.areaName
                        this.data.memberType = res.data.member.memberType
                        let mobile = "" + res.data.member.mobile
                        mobile = mobile.substr(0, 3) + "****" + mobile.substr(7, 10)
                        this.setData({
                                avatar:this.data.avatar,
                                company: res.data.member.company,
                                mobile: mobile,
                                memberType:res.data.member.memberType,
                                birthday: res.data.member.birth,
                                Invitationcod:this.data.Invitationcod,
                                promoterName:this.data.promoterName,
                                promoterMobile:this.data.promoterMobile,
                                areaName:this.data.areaName,
                        })
                        console.log(this.data.areaName)
                })
        },
        //退出账号
        loginOut: function(e) {
                wx.navigateTo({
                        url: '/pages/login/index',
                })
        }
})
